home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / KDW57K (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  4.1 KB  |  148 lines

  1. package com.sun.java.swing.text;
  2.  
  3. import java.util.Enumeration;
  4.  
  5. class StyleContext$SmallAttributeSet implements AttributeSet {
  6.    // $FF: synthetic field
  7.    StyleContext this$0;
  8.    Object[] attributes;
  9.    int nrefs;
  10.  
  11.    // $FF: synthetic method
  12.    StyleContext$SmallAttributeSet(StyleContext this$0, Object[] attributes) {
  13.       this.this$0 = this$0;
  14.       this.attributes = attributes;
  15.    }
  16.  
  17.    // $FF: synthetic method
  18.    StyleContext$SmallAttributeSet(StyleContext this$0, AttributeSet attrs) {
  19.       this.this$0 = this$0;
  20.       int n = attrs.getAttributeCount();
  21.       Object[] tbl = new Object[2 * n];
  22.       Enumeration names = attrs.getAttributeNames();
  23.  
  24.       for(int i = 0; names.hasMoreElements(); i += 2) {
  25.          tbl[i] = names.nextElement();
  26.          tbl[i + 1] = attrs.getAttribute(tbl[i]);
  27.       }
  28.  
  29.       this.attributes = tbl;
  30.    }
  31.  
  32.    Object getLocalAttribute(Object nm) {
  33.       Object[] tbl = this.attributes;
  34.  
  35.       for(int i = 0; i < tbl.length; i += 2) {
  36.          if (nm.equals(tbl[i])) {
  37.             return tbl[i + 1];
  38.          }
  39.       }
  40.  
  41.       return null;
  42.    }
  43.  
  44.    public String toString() {
  45.       String s = "{";
  46.       Object[] tbl = this.attributes;
  47.  
  48.       for(int i = 0; i < tbl.length; i += 2) {
  49.          if (tbl[i + 1] instanceof AttributeSet) {
  50.             s = s + tbl[i] + "=" + "AttributeSet" + ",";
  51.          } else {
  52.             s = s + tbl[i] + "=" + tbl[i + 1] + ",";
  53.          }
  54.       }
  55.  
  56.       s = s + "nrefs=" + this.nrefs + "}";
  57.       return s;
  58.    }
  59.  
  60.    public int hashCode() {
  61.       int code = 0;
  62.       Object[] tbl = this.attributes;
  63.  
  64.       for(int i = 1; i < tbl.length; i += 2) {
  65.          code ^= tbl[i].hashCode();
  66.       }
  67.  
  68.       return code;
  69.    }
  70.  
  71.    public boolean equals(Object obj) {
  72.       if (obj instanceof AttributeSet) {
  73.          AttributeSet attrs = (AttributeSet)obj;
  74.          return this.getAttributeCount() == attrs.getAttributeCount() && this.containsAttributes(attrs);
  75.       } else {
  76.          return false;
  77.       }
  78.    }
  79.  
  80.    public int getAttributeCount() {
  81.       return this.attributes.length / 2;
  82.    }
  83.  
  84.    public boolean isDefined(Object key) {
  85.       Object[] a = this.attributes;
  86.       int n = a.length;
  87.  
  88.       for(int i = 0; i < n; i += 2) {
  89.          if (key.equals(a[i])) {
  90.             return true;
  91.          }
  92.       }
  93.  
  94.       return false;
  95.    }
  96.  
  97.    public boolean isEqual(AttributeSet attr) {
  98.       if (attr instanceof StyleContext$SmallAttributeSet) {
  99.          return attr == this;
  100.       } else {
  101.          return this.getAttributeCount() == attr.getAttributeCount() && this.containsAttributes(attr);
  102.       }
  103.    }
  104.  
  105.    public AttributeSet copyAttributes() {
  106.       return this;
  107.    }
  108.  
  109.    public Object getAttribute(Object key) {
  110.       Object value = this.getLocalAttribute(key);
  111.       if (value == null) {
  112.          AttributeSet parent = this.getResolveParent();
  113.          if (parent != null) {
  114.             value = parent.getAttribute(key);
  115.          }
  116.       }
  117.  
  118.       return value;
  119.    }
  120.  
  121.    public Enumeration getAttributeNames() {
  122.       return new StyleContext.KeyEnumeration(this.this$0, this.attributes);
  123.    }
  124.  
  125.    public boolean containsAttribute(Object name, Object value) {
  126.       return value.equals(this.getAttribute(name));
  127.    }
  128.  
  129.    public boolean containsAttributes(AttributeSet attrs) {
  130.       boolean result = true;
  131.  
  132.       Object name;
  133.       for(Enumeration names = attrs.getAttributeNames(); result && names.hasMoreElements(); result = attrs.getAttribute(name).equals(this.getAttribute(name))) {
  134.          name = names.nextElement();
  135.       }
  136.  
  137.       return result;
  138.    }
  139.  
  140.    public AttributeSet getResolveParent() {
  141.       return (AttributeSet)this.getLocalAttribute(StyleConstants.ResolveAttribute);
  142.    }
  143.  
  144.    public Object clone() {
  145.       return this;
  146.    }
  147. }
  148.